package com.web.controller.xg;

import com.core.dto.ExcutorDTO;
import com.service.XgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author lxf
 * @date 2018/5/2 17:25
 * To change this template use Editor | File and Code Templates.
 */
@Controller
@RequestMapping("/excutor")
public class ExcutorController {

    @Autowired
    private XgService xgService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView index() {
        List<ExcutorDTO> excutorDTOs = xgService.findAllExcutor();
        return new ModelAndView("/xg/excutor", "excutorDTOs", excutorDTOs);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String saveOrUpdate(ExcutorDTO excutorDTO) {
        xgService.saveOrUpdateExcutor(excutorDTO);
        return "redirect:/excutor/list";
    }

    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public ModelAndView saveOrUpdate(String id, String name) {
        return new ModelAndView("/xg/excutorUpdate", "excutorDTO", new ExcutorDTO(id, name));
    }

    @RequestMapping(value = "del/{id}", method = RequestMethod.GET)
    public String deleteExcutor(@PathVariable String id) {
        xgService.delExcutor(id);
        return "redirect:/excutor/list";
    }

}
